<!-- 操作日志 -->
<template>
  <div class="all">
    <!-- 列表 -->
    <div class="input">
      <el-input placeholder="请输入管理员ID" v-model="listdata.targetAdminId" @keyup.enter="SearchAdmin"></el-input>
      <el-button type="primary" :icon="Search" @click="SearchAdmin">查找</el-button>
    </div>
    <el-table :data="tableData" border style="width: 100%;">
      <el-table-column prop="id" label="日志ID" align="center" />
      <el-table-column prop="adminId" label="管理员ID" align="center" />
      <el-table-column prop="requestId" label="请求ID" align="center" />
      <el-table-column prop="group" label="API分组" align="center" />
      <el-table-column prop="method" label="APi方法" align="center" />
      <el-table-column label="操作时间" align="center">
        <template #default='scope'>
          {{new Date(scope.row.gmtCreate).friendTime()}}
        </template>
      </el-table-column>
    </el-table>
    <PagingList @Change="giterList" :listdata="listdata"></PagingList>
  </div>
</template>

<script  lang="ts" setup>
import { Search } from '@element-plus/icons-vue'
import { ref, reactive } from "vue";
import { post } from "@/utils/request";
import { ElMessage } from 'element-plus';
import {Pagination} from "#/index";


const tableData:TypeLog[] = reactive([]) //表格数据
// const Administratorid = ref('') //搜索管理员id
// const pageNum = ref(1) // 页码
// const pageSize = ref(10) //每一页要显示的页面
// const count = ref(0) //总数量
// const flog = ref(false)

let listdata = reactive(new Pagination());

// 接收父组件传的值
const giterList = (e: any) => {
  listdata = e;
  Operation();
};

// 初始化数据
const Operation = () => {
  // let data = {
  //   _gp: 'admin.log',
  //   _mt: 'list',
  //   targetAdminId:listdata.targetAdminId,
  //   page: listdata.page,
  //   limit: listdata.limit

  // }
  let data
  if (listdata.flog) {
    data = {
      _gp: 'admin.log',
      _mt: 'list',
      targetAdminId: listdata.targetAdminId,
      page: listdata.page,
      limit: listdata.limit
    }
  } else {
    data = {
      _gp: 'admin.log',
      _mt: 'list',
      page: listdata.page,
      limit: listdata.limit
    }
  }
  post(data).then(res => {
    const { errno, errmsg, data } = res
    if (200 == errno) {
      tableData.length = 0
      tableData.push(...data.items)
      listdata.total = data.total
    } else {
      ElMessage.error(errmsg)
    }
  })
}
Operation()

// 搜索管理员ID
const SearchAdmin = () => {
  if (!Number(listdata.targetAdminId) && listdata.targetAdminId != null) {
    ElMessage.warning("请输入管理员ID")
    return
  } else {
    listdata.flog = true
    listdata.page = 1
    Operation()
  }
}


</script>

<style lang="less" scoped>
.all {
  overflow-x: hidden;

  .input {
    margin-bottom: 15px;

    .el-input {
      width: 270px;
      height: 30px;
    }

    .el-button {
      height: 30px;
      margin-left: 15px;
    }
  }
}
</style>
